import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'
import houseOpt from '@/biz/option/house.js'
import dateOpt from '@/biz/option/date.js'
import nameOpt from '@/biz/option/name.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    let list = [{
      title: '事业部',
      field: 'divisionName',
      minWidth: 120,
    }, {
      title: '分公司',
      field: 'companyName',
      minWidth: 120,
    }, {
      title: '事业处',
      field: 'officeName',
      minWidth: 120,
    }, {
      title: '案场',
      field: 'buildingName',
      minWidth: 120,
      header: {
        filter: {
          key: 'buildingName',
          title: '案场',
          input: {},
          placeholder: '请输入案场'
        }
      }
    }]
    console.log(_this.orgId, '7878')

    if (_this.orgId) {
      this.all.splice(0, 0, ...list)
    }
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
    {
      title: '人员',
      field: 'userWorkName',
      minWidth: 120,
      header: {
        filter: {
          key: 'searchKey',
          title: '人员',
          input: {},
          placeholder: '请输入人员名称或工号'
        }
      }
    },
    {
      title: '导入文章',
      field: 'title',
      minWidth: 220,
      slots: {
        default: (params, h) => {
          return table.cell.btn(_this, h, {
            title: params.row.title,
            event: 'viewFun',
            data: params.row
          })
        }
      }
    },
    {
      title: '导入时间',
      field: 'createDate',
      minWidth: 160,
      cell: {
        text: {}
      },
      header: {
        filter: dateOpt.range({
          title: '导入时间',
          startKey: 'createDate',
          endKey: 'endDate'
        })
      },
    },
    {
      title: '微信好友阅读量',
      field: 'viewCount',
      minWidth: 150,
      remoteSort: true,
    },
    {
      title: '朋友圈阅读量',
      field: 'pyqViewCount',
      minWidth: 130,
      remoteSort: true,
    },
    {
      title: '状态',
      field: 'deleteFlagValue',
      minWidth: 100,
      header: {
        filter: {
          title: '状态',
          key: 'deleteFlag',
          placeholder: '请选择',
          select: {
            options: [
              { key: '1', value: '正常' },
              { key: '0', value: '已删除' }
            ],
          }
        }
      },
    },
    {
      title: '操作',
      fixed: 'right',
      minWidth: 130,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: '查看',
            event: 'viewFun',
            data: params.row
          })
          if (params.row.deleteFlagValue == '正常' && ((!_this.orgId && _this.unlocking(
              '0107090100')) || (_this.orgId && _this.unlocking('0207030301')))) {
            btns.push({
              title: '删除文章',
              event: 'delFun',
              data: params.row
            })
          }
          return table.cell.btns(_this, h, btns)
        }
      }
    }]

  }

}

export default Column